// Copyright (c) 2015-2019 The HomeKit ADK Contributors
//
// Licensed under the Apache License, Version 2.0 (the “License”);
// you may not use this file except in compliance with the License.
// See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.

#include "HAPPlatformAccessorySetup+Init.h"

static const HAPLogObject logObject = { .subsystem = kHAPPlatform_LogSubsystem, .category = "AccessorySetup" };

static const HAPSetupInfo kHAPPlatformAccessorySetup_SetupInfo = {
    // Setup code: 111-22-333
    .salt = { 0x93, 0x15, 0x1A, 0x47, 0x57, 0x55, 0x3C, 0x21, 0x0B, 0x55, 0x89, 0xB8, 0xC3, 0x99, 0xA0, 0xF3 },
    .verifier = { 0x9E, 0x9C, 0xC3, 0x73, 0x9B, 0x04, 0x83, 0xC8, 0x13, 0x7C, 0x5B, 0x5F, 0xAC, 0xC5, 0x63, 0xDF, 0xF4,
                  0xF1, 0x0F, 0x39, 0x06, 0x4A, 0x20, 0x2D, 0x53, 0x2A, 0x09, 0x20, 0x3A, 0xA6, 0xBA, 0xE3, 0x1E, 0x42,
                  0x4E, 0x58, 0x4E, 0xBB, 0x44, 0x5F, 0x7F, 0xDF, 0xCC, 0x11, 0xD0, 0xF7, 0x8B, 0x35, 0xE1, 0x16, 0xA9,
                  0x79, 0x30, 0xBC, 0x37, 0x19, 0x77, 0x36, 0xB1, 0xEC, 0xD4, 0x12, 0x4C, 0xE4, 0x5D, 0xE3, 0x7E, 0x46,
                  0xA0, 0x2D, 0x10, 0x07, 0xAB, 0x48, 0x40, 0x36, 0xD5, 0x3F, 0x7F, 0xBE, 0xA5, 0xAE, 0xD0, 0x25, 0x6B,
                  0xC4, 0x9E, 0xC8, 0x5F, 0xC9, 0x4E, 0x47, 0x0D, 0xBA, 0xD3, 0x63, 0x44, 0x20, 0x01, 0x69, 0x97, 0xDD,
                  0x20, 0x54, 0x7C, 0x59, 0x78, 0x3D, 0x5C, 0x6D, 0xC7, 0x1F, 0xE6, 0xFD, 0xA0, 0x8E, 0x9B, 0x36, 0x45,
                  0x1F, 0xC1, 0x4B, 0xB5, 0x26, 0xE1, 0x8E, 0xEB, 0x4C, 0x05, 0x58, 0xD7, 0xC8, 0x80, 0xA1, 0x43, 0x7F,
                  0x5F, 0xDB, 0x75, 0x1B, 0x19, 0x57, 0x25, 0xAC, 0x5D, 0xF5, 0x8D, 0xF6, 0x7B, 0xAA, 0xB7, 0x7D, 0xE0,
                  0x36, 0xEF, 0xEA, 0xF3, 0x57, 0xAC, 0xFE, 0x12, 0x87, 0xF9, 0x31, 0x4C, 0xF7, 0x44, 0xBD, 0xB6, 0x26,
                  0x6C, 0xB4, 0x0D, 0x7C, 0x52, 0x4F, 0x85, 0x56, 0x91, 0x5D, 0x13, 0xD8, 0xDA, 0x8C, 0x45, 0x3E, 0x73,
                  0xF2, 0xF9, 0x20, 0x39, 0x24, 0x8B, 0xFB, 0xEE, 0xFD, 0x77, 0x54, 0x8D, 0x37, 0x22, 0xE8, 0x55, 0xC3,
                  0xD2, 0xF8, 0xB8, 0x23, 0xB0, 0xE2, 0x9E, 0x43, 0xAE, 0xB4, 0x37, 0xFA, 0xA7, 0x03, 0xF1, 0x82, 0x68,
                  0x4C, 0xD4, 0x86, 0xC6, 0x3E, 0xDE, 0x70, 0x11, 0x03, 0x77, 0x46, 0x59, 0x14, 0x97, 0xC6, 0xAE, 0x52,
                  0x6F, 0x03, 0x77, 0x36, 0x40, 0xBC, 0xDE, 0xCD, 0x3D, 0xE0, 0x4F, 0x69, 0x18, 0x0D, 0xCA, 0x85, 0x7E,
                  0x07, 0x30, 0xF4, 0xA1, 0xCE, 0x05, 0xB5, 0x4B, 0xE1, 0x1D, 0x43, 0xDF, 0xDB, 0x11, 0x43, 0xDE, 0x21,
                  0xAC, 0x8F, 0x03, 0x9E, 0x6E, 0x9F, 0xA8, 0xE5, 0x02, 0x06, 0x1C, 0x63, 0x34, 0x22, 0x1D, 0x39, 0xE3,
                  0x3D, 0x12, 0x2E, 0xA2, 0xF3, 0xFC, 0xB5, 0xB4, 0x16, 0x9E, 0x0E, 0x7C, 0x52, 0xC8, 0x7D, 0x50, 0x3D,
                  0xDB, 0xF5, 0x83, 0x46, 0x18, 0x92, 0x7F, 0x4D, 0x38, 0xAD, 0x0A, 0x2A, 0xBC, 0x2A, 0x50, 0x4B, 0xDF,
                  0x5D, 0xFA, 0x93, 0x41, 0x78, 0xD6, 0x45, 0x54, 0xDB, 0x44, 0x81, 0xF7, 0x5A, 0x0A, 0xDD, 0x18, 0x4F,
                  0x27, 0xD7, 0xDD, 0x5E, 0xB7, 0x3E, 0x99, 0xE6, 0xE1, 0x69, 0x35, 0x74, 0xD6, 0x98, 0x58, 0xB2, 0x13,
                  0x6F, 0xB7, 0x82, 0x72, 0xBC, 0xA6, 0x8B, 0xA3, 0x36, 0x2A, 0xCE, 0x65, 0x65, 0x51, 0x08, 0x8A, 0x3D,
                  0x04, 0x93, 0x8F, 0x01, 0x8A, 0xAB, 0x4B, 0xFC, 0x06, 0xF9 }
};

void HAPPlatformAccessorySetupCreate(
        HAPPlatformAccessorySetupRef _Nonnull accessorySetup,
        const HAPPlatformAccessorySetupOptions* _Nonnull options)

{
    HAPPrecondition(accessorySetup);
    HAPPrecondition(options);
}

void HAPPlatformAccessorySetupLoadSetupInfo(
        HAPPlatformAccessorySetupRef _Nonnull accessorySetup,
        HAPSetupInfo* _Nonnull setupInfo) {
    HAPPrecondition(accessorySetup);
    HAPPrecondition(setupInfo);

    HAPLog(&logObject, "Using constant setup code implementation - must not be used for production accessories!");
    *setupInfo = kHAPPlatformAccessorySetup_SetupInfo;
}

void HAPPlatformAccessorySetupLoadSetupCode(
        HAPPlatformAccessorySetupRef _Nonnull accessorySetup,
        HAPSetupCode* _Nonnull setupCode) {
    HAPPrecondition(accessorySetup);
    HAPPrecondition(setupCode);

    HAPLogError(&logObject, "[NYI] %s.", __func__);
    HAPFatalError();
}

void HAPPlatformAccessorySetupLoadSetupID(
        HAPPlatformAccessorySetupRef _Nonnull accessorySetup,
        bool* _Nonnull valid,
        HAPSetupID* _Nonnull setupID) {
    HAPPrecondition(accessorySetup);
    HAPPrecondition(valid);
    HAPPrecondition(setupID);

    *valid = false;
}

//----------------------------------------------------------------------------------------------------------------------
// Deprecated APIs.

HAP_DEPRECATED_MSG("Return false and use HAPPlatformAccessorySetupDisplay / HAPPlatformAccessorySetupNFC instead.")
HAP_RESULT_USE_CHECK
HAPPlatformAccessorySetupCapabilities
        HAPPlatformAccessorySetupGetCapabilities(HAPPlatformAccessorySetupRef _Nonnull accessorySetup) {
    HAPPrecondition(accessorySetup);

    // Deprecated. Return false and use HAPPlatformAccessorySetupDisplay / HAPPlatformAccessorySetupNFC instead.
    return (HAPPlatformAccessorySetupCapabilities) { .supportsDisplay = false, .supportsProgrammableNFC = false };
}

void HAPPlatformAccessorySetupUpdateSetupPayload(
        HAPPlatformAccessorySetupRef _Nonnull accessorySetup,
        const HAPSetupPayload* _Nullable setupPayload,
        const HAPSetupCode* _Nullable setupCode) {
    HAPPrecondition(accessorySetup);

    (void) setupPayload;
    (void) setupCode;
    HAPLogError(&logObject, "[NYI] %s.", __func__);
    HAPFatalError();
}
